<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page language="java" import="com.sinodata.bsm.common.vo.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>resource-dimensions-config-update</title>
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/form.jsp"%>
	<%@ include file="../include/tree.jsp"%>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/style/default/easyui/easyui.css">
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jquery.easyui.min.js"></script>
	  <style type="text/css">
		.ztree {border: 1px solid #617775;background: #f0f6e4;width:220px;height:360px;overflow-y:scroll;overflow-x:auto;}
	</style>   
	<script type="text/javascript">
		var flag ;
  		var id = '${resDimension.queryDimension.id}';
  		var setting = {
  				check: {
  					enable: true,
  					chkboxType: {"Y" : "ps", "N" : "ps"}
  				},
  				view: {
  					dblClickExpand: false
  				},
  				data: {
  					simpleData: {
  						enable: true
  					}
  				},
  				callback: {
  					onCheck: onCheck
  				}
  		};
		function onCheck(e, treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			nodes = zTree.getCheckedNodes(true),
			v = "";
			m = "";
			for (var i=0, l=nodes.length; i<l; i++) {
				v += nodes[i].name + ",";
				m += nodes[i].id + ",";
			}
			if (v.length > 0 ) v = v.substring(0, v.length-1);
			if (m.length > 0 ) m = m.substring(0, m.length-1);
			if(flag == 1){
				var cityObj = $("#firstDimScope");
				cityObj.attr("value", v);
				$("#firstDimScope1").val(m);
			}
			if(flag == 2){
				var cityObj = $("#secondDimScope");
				cityObj.attr("value", v);
				$("#secondDimScope1").val(m);
			}
			if(flag == 3){
				var cityObj = $("#thirdDimScope");
				cityObj.attr("value", v);
				$("#thirdDimScope1").val(m);
			}
		}
		
		function showMenu(date1) {
			flag = date1;
			var date;
			if(flag == 1){
				date = "dimCode="+$("#firstDimCode").val()+"&dimLevel="+$("#firstDimLevel").val()+"&id="+id+"&flag="+'1'+"&dimScope="+$("#firstDimScope1").val();
			}
			if(flag == 2){
				date = "dimCode="+$("#secondDimCode").val()+"&dimLevel="+$("#secondDimLevel").val()+"&id="+id+"&flag="+'2'+"&dimScope="+$("#secondDimScope1").val();
			}
			if(flag == 3){
				date = "dimCode="+$("#thirdDimCode").val()+"&dimLevel="+$("#thirdDimLevel").val()+"&id="+id+"&flag="+'3'+"&dimScope="+$("#thirdDimScope1").val();
			}
			$.ajax({ 
				  type:"post", 
				  url:"${pageContext.request.contextPath}/config/resource-dimension-config!dimScopeList.action", 
				  data:date, 
				  datatype:"json",
				  success:function(data) { 
						var zNodes=eval(data);
						$.fn.zTree.init($("#treeDemo"), setting, zNodes);
						
						if(flag == 1){
							var cityObj = $("#firstDimScope");
							var cityOffset = $("#firstDimScope").offset();
							$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
							$("body").bind("mousedown", onBodyDown);
						}
						if(flag == 2){
							var cityObj = $("#secondDimScope");
							var cityOffset = $("#secondDimScope").offset();
							$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
							$("body").bind("mousedown", onBodyDown);
						}
						if(flag == 3){
							var cityObj = $("#thirdDimScope");
							var cityOffset = $("#thirdDimScope").offset();
							$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
							$("body").bind("mousedown", onBodyDown);
						}
				  } 
		     	})
		}
		
		function hideMenu() {
			$("#menuContent").fadeOut("fast");
			$("body").unbind("mousedown", onBodyDown);
		}
		function onBodyDown(event) {
			if (!(event.target.id == "menuBtn" || event.target.id == "firstDimScope" || event.target.id == "secondDimScope"|| event.target.id == "thirdDimScope"|| event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
				hideMenu();
			}
		}
  
  	$(function(){
	  $.formValidator.initConfig({formid:"myform"
          ,onerror:function(msg){}
          ,onsuccess:function(){
        	 		 edit();
          			return false;
          }
    });
	  $("#name").formValidator({onshow:"必输项",onfocus:"必输项 长度(1-64)",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"不能为空"}).inputValidator({min:1,max:64,onerror:"长度非法"});
		$("#order").formValidator({onshow:"请输入数字",onfocus:"请输入数字 长度(1-5)",oncorrect:"输入正确"}).inputValidator({min:1,onerror:"不能为空"}).inputValidator({min:1,max:5,onerror:"长度范围(1-5)"})
		  .functionValidator({
				    fun:function(val,elem){
				    	 var reg = /^[0-9]+$/;
				    	    if(!reg.test(val)){
				    	        return "必须为整数";
				    	    }
				    	    return true;
					}
		  });
		$("#secondDimLevel").formValidator({onshow:"可以不填  范围(1-10)",onfocus:"可以不填  范围(1-10)",oncorrect:"输入正确"})
		  .inputValidator({min:0,max:10,type:"value",onerror:"范围(1-10)"});
		$("#thirdDimLevel").formValidator({onshow:"可以不填  范围(1-10)",onfocus:"可以不填  范围(1-10)",oncorrect:"输入正确"})
		  .inputValidator({min:0,max:10,type:"value",onerror:"范围(1-10)"});
		$("#firstDimLevel").formValidator({onshow:"可以不填  范围(1-10)",onfocus:"可以不填  范围(1-10)",oncorrect:"输入正确"})
		 .inputValidator({min:0,max:10,type:"value",onerror:"范围(1-10)"});
	
	pageInit();
	$("#firstDimCode").change(function(){
		var firstDimCode = $("#firstDimCode").val();
		$.ajax({
			   type: "post", 
			   url: "${pageContext.request.contextPath}/config/resource-dimension-config!dimCodeListSecond.action?firstDimCode="+firstDimCode,
			   data: "", //传的参数
			   async:false,
			   dataType: "json",
			   success: function(data){ //结果
				   var obj= document.getElementById("secondDimCode");
				   obj.length=0;
			   	   for(var i = 0 ;i<data.length;i++){
						obj.options[i]=new Option(data[i].name,data[i].id);
			   	   }
			   }
			  
		});
		var obj= document.getElementById("thirdDimCode");
		obj.length=0;
		$("#firstDimScope").val('');
		  $("#firstDimScope1").val('');
		$("#secondDimScope").val('');
		  $("#secondDimScope1").val('');
		  $("#thirdDimScope").val('');
		  $("#thirdDimScope1").val('');
		  $("#firstDimLevel").val('');
			$("#secondDimLevel").val('');
			$("#thirdDimLevel").val('');
		id= -1;
	});
	$("#secondDimCode").change(function(){
		var firstDimCode = $("#firstDimCode").val();
		var secondDimCode = $("#secondDimCode").val();
		$.ajax({
			   type: "post", 
			   url: "${pageContext.request.contextPath}/config/resource-dimension-config!dimCodeListThird.action?firstDimCode="+firstDimCode+"&secondDimCode="+secondDimCode,
			   data: "", //传的参数
			   async:false,
			   dataType: "json",
			   success: function(data){ //结果
				   var obj= document.getElementById("thirdDimCode");
				   obj.length=0;
			   	   for(var i = 0 ;i<data.length;i++){
						obj.options[i]=new Option(data[i].name,data[i].id);
			   	   }
			   }
			  
		});
		$("#secondDimScope").val('');
		  $("#secondDimScope1").val('');
		  $("#thirdDimScope").val('');
		  $("#thirdDimScope1").val('');
			$("#secondDimLevel").val('');
			$("#thirdDimLevel").val('');
			id= -1;
	});
	$("#thirdDimCode").change(function(){
		  $("#thirdDimScope").val('');
		  $("#thirdDimScope1").val('');
			$("#thirdDimLevel").val('');
			id= -1;
	});
  })
  	function closewin(){
  	  getTopWin(window).closejBox("update-resource-dimensions-config");
    	}
  	function edit(){
  		$("#id").val('${resDimension.queryDimension.id}');
	  	//提交
  		$.ajax({
			   type: "POST", 
			   url: "${pageContext.request.contextPath}/config/resource-dimension-config!save.action", //请求的action
			   data: $("#myform").serialize(), //传的参数
			   dataType: 'json',
			   success: function(data){ //结果
					   var pWin = getTopWin(window).currentWin["update-resource-dimension-config"];
					   pWin.datagrid();
					   getTopWin(window).closejBox("update-resource-dimension-config");
			   }
		});
	}
  	function pageInit(){
  		$.ajax({
			   type: "post", 
			   url: "${pageContext.request.contextPath}/config/resource-dimension-config!dimCodeListFirst.action?dimCode="+${resDimension.queryDimension.firstDimCode},
			   data: "", //传的参数
			   async:false,
			   dataType: "json",
			   success: function(data){ //结果
				   var obj= document.getElementById("firstDimCode");
				   obj.length=0;
			   	   for(var i = 0 ;i<data.length;i++){
						obj.options[i]=new Option(data[i].name,data[i].id);
			   	   }
			   }
			  
		});
  		if('${resDimension.queryDimension.firstDimCode}' != ''){
  			$.ajax({
 			   type: "post", 
 			   url: "${pageContext.request.contextPath}/config/resource-dimension-config!dimCodeListSecond.action?firstDimCode="+'${resDimension.queryDimension.firstDimCode}',
 			   data: "", //传的参数
 			   async:false,
 			   dataType: "json",
 			   success: function(data){ //结果
 				   var obj= document.getElementById("secondDimCode");
 				   obj.length=0;
 			   	   for(var i = 0 ;i<data.length;i++){
 						obj.options[i]=new Option(data[i].name,data[i].id);
 			   	   }
 			   }
 			});
  		}
  		if('${resDimension.queryDimension.secondDimCode}' != ''){
	  		$.ajax({
				   type: "post", 
				   url: "${pageContext.request.contextPath}/config/resource-dimension-config!dimCodeListThird.action?firstDimCode="+'${resDimension.queryDimension.firstDimCode}'+"&secondDimCode="+'${resDimension.queryDimension.secondDimCode}',
				   data: "", //传的参数
				   async:false,
				   dataType: "json",
				   success: function(data){ //结果
					   var obj= document.getElementById("thirdDimCode");
					   obj.length=0;
				   	   for(var i = 0 ;i<data.length;i++){
							obj.options[i]=new Option(data[i].name,data[i].id);
				   	   }
				   }
			});
  		}
  		$("#firstDimCode").val('${resDimension.queryDimension.firstDimCode}');
  		$("#secondDimCode").val('${resDimension.queryDimension.secondDimCode}');
  		$("#thirdDimCode").val('${resDimension.queryDimension.thirdDimCode}');
  		$("#firstDimLevel").val('${resDimension.queryDimension.firstDimLevel}');
  		$("#secondDimLevel").val('${resDimension.queryDimension.secondDimLevel}');
  		$("#thirdDimLevel").val('${resDimension.queryDimension.thirdDimLevel}');
  		$("#firstDimScope").val('${resDimension.firstDimScopeName}');
  		$("#secondDimScope").val('${resDimension.secondDimScopeName}');
  		$("#thirdDimScope").val('${resDimension.thirdDimScopeName}');
  		$("#firstDimScope1").val('${resDimension.queryDimension.firstDimScope}');
  		$("#secondDimScope1").val('${resDimension.queryDimension.secondDimScope}');
  		$("#thirdDimScope1").val('${resDimension.queryDimension.thirdDimScope}');
  	}
  	function pageReset(){
		  $("#myform").get()[0].reset(); 
		  id = '${resDimension.queryDimension.id}';
		  pageInit();
	}

  	var oldFirstDimLevel;
	var newFirstDimLevel;
	function firstDimLevelOnBlur(){
		newFirstDimLevel = $("#firstDimLevel").val();
		if(newFirstDimLevel != oldFirstDimLevel){
			id = -1;
			  $("#firstDimScope").val('');
			  $("#firstDimScope1").val('');
		}
	}
	function firstDimLevelOnFocus(){
		oldFirstDimLevel = $("#firstDimLevel").val();
	}
	
	var oldSecondDimLevel;
	var newSecondDimLevel;
	function secondDimLevelOnBlur(){
		newSecondDimLevel = $("#secondDimLevel").val();
		if(newSecondDimLevel != oldSecondDimLevel){
			id = -1;
			  $("#secondDimScope").val('');
			  $("#secondDimScope1").val('');
		}
	}
	function secondDimLevelOnFocus(){
		oldSecondDimLevel = $("#secondDimLevel").val();
	}
	
	var oldThirdDimLevel;
	var newThirdDimLevel;
	function thirdDimLevelOnBlur(){
		newThirdDimLevel = $("#thirdDimLevel").val();
		if(newThirdDimLevel != oldThirdDimLevel){
			id = -1;
			  $("#thirdDimScope").val('');
			  $("#thirdDimScope1").val('');
		}
	}
	function thirdDimLevelOnFocus(){
		oldThirdDimLevel = $("#thirdDimLevel").val();
	}
  </script>
  </head>
  
  <body class="padding-8">
  <div id="menuContent" class="menuContent" style="display:none; position: absolute;">
	<ul id="treeDemo" class="ztree" style="margin-top:0; width:200px; height: 200px;"></ul>
</div>
    <form action="" id="myform" name="myform" method="post">
	 	<li><h2 class="title-h2">基本信息</h2></li>
	 	<table class="table_eidt">
    			<tr>
	    			<td class="td_left" width="100px"><span class="span_alert">*</span>查询名称</td>
	    			<td class="td_right"><input type="text" name="name" id="name" style="width:225px" value=${resDimension.queryDimension.name}>
	    			<span id="nameTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
    				<td class="td_left" style="vertical-align: top;">描述</td>
    				<td class="td_right">
    					<textarea rows="4" cols="1" id="desc" name="desc" style="width:225px">${resDimension.queryDimension.desc}</textarea>
    				</td>
    			</tr>
    			<tr>
	    			<td class="td_left"><span class="span_alert">*</span>显示序号</td>
	    			<td class="td_right"><input type="text" name="order" id="order" style="width:225px" value=${resDimension.queryDimension.order}>
	    			<span id="orderTip" style="width:150px"></span></td>
    			</tr>
    			</table>
		    			<li><h2 class="title-h2">第一维度</h2></li>
		    	<table class="table_eidt">
    			<tr>
	    			<td class="td_left" width="100px">选择维度</td>
	    			<td class="td_right">
	    				<select name="firstDimCode" id="firstDimCode" style="width:225px">
				        </select>
			        </td>
    			</tr>
    			<tr>
	    			<td class="td_left">级别限制</td>
	    			<td class="td_right" ><input type="text" name="firstDimLevel" id="firstDimLevel" style="width:225px"  onblur="firstDimLevelOnBlur();" onfocus="firstDimLevelOnFocus();">
    				<span id="firstDimLevelTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
	    			<td class="td_left">范围限制</td>
	    			<td class="td_right">
	    			<input id="firstDimScope" type="text" name="firstDimScope" readonly  style="width:225px;" onclick="showMenu(1);" />
			        </td>
    			</tr>
    			</table>
		    			<li><h2 class="title-h2">第二维度</h2></li>
		    	<table class="table_eidt">
    			<tr>
	    			<td class="td_left" width="100px">选择维度</td>
	    			<td class="td_right"><div onclick="secondDimCodeClick();">
	    			<select name="secondDimCode" id="secondDimCode" style="width:225px">
			        </select></div>
			        </td>
    			</tr>
    			<tr>
	    			<td class="td_left">级别限制</td>
	    			<td class="td_right"><input type="text" name="secondDimLevel" id="secondDimLevel" style="width:225px" onblur="secondDimLevelOnBlur();" onfocus="secondDimLevelOnFocus();">
    				<span id="secondDimLevelTip" style="width:150px"></span></td>
    			</tr>
    			<tr>
	    			<td class="td_left">范围限制</td>
	    			<td class="td_right">
	    			<input id="secondDimScope" type="text" name="secondDimScope" readonly style="width:225px;" onclick="showMenu(2);" />
					</td>
    			</tr>
    			</table>
		    			<li><h2 class="title-h2">第三维度</h2></li>
		    	<table class="table_eidt">
    			<tr style="height: 35px">
	    			<td class="td_left" width="100px">选择维度</td>
	    			<td class="td_right"><div onclick="thirdDimCodeClick();"><select name="thirdDimCode" id="thirdDimCode" style="width:225px">
			        </select></div></td>
    			</tr>
    			<tr>
	    			<td class="td_left">级别限制</td>
	    			<td class="td_right"><input type="text" name="thirdDimLevel" id="thirdDimLevel" style="width:225px" onblur="thirdDimLevelOnBlur();" onfocus="thirdDimLevelOnFocus();">
	    			<span id="thirdDimLevelTip" style="width:200px"></span></td>
    			</tr>
    			<tr>
	    			<td class="td_left">范围限制</td>
	    			<td class="td_right">
	    				<input id="thirdDimScope" type="text" name="thirdDimScope" readonly  style="width:225px;" onclick="showMenu(3);" />
	    			</td>
    			</tr>
    		</table>
    		<div align="center" style="margin-top:5px;">
	    		<input type="submit" id="button" name="button" value="保存" class="btn-4">
	    		<input type="button" value="重置" class="btn-4" onclick="pageReset();">
	    		<input type="button" value="取消" onclick="closewin();" class="btn-4">
    		</div>
    		<input id="id" type="text" name="id" style="visibility: hidden;"/>
    		<input id="firstDimScope1" type="text" name="firstDimScope1"  style="visibility: hidden;"/>
    		<input id="secondDimScope1" type="text" name="secondDimScope1" style="visibility: hidden;"/>
    		<input id="thirdDimScope1" type="text" name="thirdDimScope1"  style="visibility: hidden;"/>
	</form>
  </body>
</html>
